package com.hspedu.newData.dmsxl.栈;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-23 
 * @Version: 1.0
 */


// todo
public class LC20有效的括号 {

    public boolean isValid(String s) {

        Map<Character,Character> map = new HashMap<>();
        map.put(')','(');
        map.put(']','[');
        map.put('}','{');
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (!stack.isEmpty() && map.get(s.charAt(i)) == stack.peek()){
                stack.pop();
            }else {
                stack.add(s.charAt(i));
            }
        }
        return stack.isEmpty();
    }

    @Test
    public void test() {

        // 测试代码
        boolean valid = isValid("({)[]");

        System.out.println("========");

    }
}
